package com.example.administrator.yuejian35.Home.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.administrator.yuejian35.BaseListAdapter;
import com.example.administrator.yuejian35.Config;
import com.example.administrator.yuejian35.Home.activity.MasterActivity;
import com.example.administrator.yuejian35.Home.bean.Course;
import com.example.administrator.yuejian35.Home.bean.Master;
import com.example.administrator.yuejian35.R;
import com.example.administrator.yuejian35.RoundTransform;
import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * Created by Wolfh on 2017/4/29.
 */

public class MasterAdapter extends BaseListAdapter {

    public MasterAdapter(Context context, List list){
        super(context, list);

    }

    @Override
    protected RecyclerView.ViewHolder onCreateVH(ViewGroup parent, LayoutInflater layoutInflater, int viewType) {
        View ItemView = layoutInflater.inflate(R.layout.item_master,parent,false);

        MasterViewHolder viewHolder = new MasterViewHolder(ItemView);//定义显示部件

        return viewHolder;
    }

    @Override
    protected void onBindVH(RecyclerView.ViewHolder holder, int position, List data) {
        final Master master = (Master) data.get(position);

        if(holder instanceof  MasterViewHolder){

            MasterViewHolder viewHolder = (MasterViewHolder) holder;


            viewHolder.name.setText(master.getCoachname());
            viewHolder.like.setText(master.getCoachattention());

            Picasso.with(context)
                    .load(Config.MasterImages_URL+master.getCoachpic())
                    .transform(new RoundTransform(50))
                    .into(viewHolder.pic);

            viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {

                    Intent intent = new Intent(context, MasterActivity.class);

                    intent.putExtra("master",master);

                    context.startActivity(intent);

                }
            });



        }
    }


}
